package com.atguigu.servlet;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

public class Servlet07ServletContextRead extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext servletContext = getServletContext();

        // 从应用域读取数据：要使用和存入时一样的属性名
        Object attrValue = servletContext.getAttribute("attrNameApp");

        resp.setContentType("text/html;charset=utf-8");
        resp.getWriter().write(attrValue.toString());
    }
}
